<?php
$this->breadcrumbs=array(
	'Carga Semestral'=>array('admin'),
	'Criar',
);

Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/assets/884ba3ad/gridview/styles.css');
Yii::app()->clientScript->registerCss('id', '.row{margin-top:10px;}.hidden{display:none;}');
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/cargaSemestral.js');
?>
<?php echo $this->renderPartial('../layouts/mensagemErro', array('model' => $model)); ?>

<h1>Criar Carga Semestral</h1>
<div class="form">
    <?php $form=$this->beginWidget('CActiveForm', array(
            'id'=>'template-form',
            'enableAjaxValidation'=>false,
    )); ?>

    <p class="note">Campos com <span class="required">*</span> são obrigatórios.</p>

    <?php echo $form->errorSummary($model); ?>
    <div id="modelo">
        <div class="row sameLine">
            <?php echo $form->labelEx($model,'NU_ANO'); ?>
            <?php echo $form->textField($model,'NU_ANO', array('size'=>10,'maxlength'=>4, 'alt'=>'9999')); ?>
            <?php echo $form->error($model,'NU_ANO'); ?>
        </div>
        <div class="row sameLine">
            <?php echo $form->labelEx($model,'NU_SEMESTRE'); ?>
            <?php echo $form->dropDownList($model,'NU_SEMESTRE', array(1=>'1',2=>'2'), array('style'=>'width:100%')); ?>
            <?php echo $form->error($model,'NU_SEMESTRE'); ?>
        </div>
        <div class="row sameLine">
            <?php echo $form->labelEx($model,'DT_INI'); ?>
            <?php Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
                $this->widget('CJuiDateTimePicker',array(
                    'model'=>$model, //Model object
                    'attribute'=>'DT_INI', //attribute name
                    'mode'=>'date', //use "time","date" or "datetime" (default)
                    'options'=>array(
                        'minDate'=> '0',
                        'dateFormat'=>'dd/mm'
                    ),
                    'htmlOptions'=>array(
                        'size'=>10
                    )
                ));
            ?>
            <?php echo $form->error($model,'DT_INI'); ?>
        </div>
        <div class="row sameLine">
            <?php echo $form->labelEx($model,'DT_FIM'); ?>
            <?php Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
                $this->widget('CJuiDateTimePicker',array(
                    'model'=>$model, //Model object
                    'attribute'=>'DT_FIM', //attribute name
                    'mode'=>'date', //use "time","date" or "datetime" (default)
                    'options'=>array(
                        'minDate'=> '0',
                        'dateFormat'=>'dd/mm'
                    ),
                    'htmlOptions'=>array(
                        'size'=>10
                    )
                ));
            ?>
            <?php echo $form->error($model,'DT_FIM'); ?>
        </div>
        <div class="row sameLine">
            <?php echo $form->labelEx($model,'TX_NOME'); ?>
            <?php echo $form->textField($model,'TX_NOME',array('size'=>50,'maxlength'=>50)); ?>
            <?php echo $form->error($model,'TX_NOME'); ?>
        </div>
    </div>
    <div id="disciplina">
        <div class="row sameLine">
            <label for="ID_DISCIPLINA">Disciplina<span class="required">*</span></label>
            <?php
                $dados = Disciplina::model()->getDisciplinas();
                echo CHtml::dropDownList('ID_DISCIPLINA','', $dados,'');
            ?>
            <br/>
        </div>
        <div class="row sameLine">
            <label for="Turma">Turma<span class="required">*</span></label>
            <?php
                echo CHtml::textField('Turma', '', array('id'=>'Turma','size'=>10)); 
            ?>
            <br/>
        </div>
        <div class="row chkListH">
            <label>Dias da Semana<span class="required">*</span></label><br/>
            <input type="checkbox" class="dias" id="DIAS_0" value="0" style="clear:left"> <label for="DIAS_0">Domingo</label>
            <input type="checkbox" class="dias" id="DIAS_1" value="1"> <label for="DIAS_1">Segunda</label>
            <input type="checkbox" class="dias" id="DIAS_2" value="2"> <label for="DIAS_2">Terça</label>
            <input type="checkbox" class="dias" id="DIAS_3" value="3"> <label for="DIAS_3">Quarta</label>
            <input type="checkbox" class="dias" id="DIAS_4" value="4"> <label for="DIAS_4">Quinta</label>
            <input type="checkbox" class="dias" id="DIAS_5" value="5"> <label for="DIAS_5">Sexta</label>
            <input type="checkbox" class="dias" id="DIAS_6" value="6"> <label for="DIAS_6">Sabado</label>
            <br/>
        </div>
        <div class="row sameLine" style="clear:left">
            <label>Finalidade<span class="required">*</span></label>
            <?php
                $dados = $modelAU->getUsos();
                echo CHtml::dropDownList('', '', $dados, array('id'=>'Finalidade'));
                //echo $form->checkBoxList($modelAR, 'ID_RECURSO', $dados);
                //echo $form->textField($modelAR, 'NU_QUANTIDADE', array('name'=>'Ambiente_Recurso[NU_QUANTIDADE][]'));
            ?>
        </div>
        <div class="row sameLine">
            <label for="Capacidade">Capacidade<span class="required">*</span></label>
            <?php
                echo CHtml::textField('Capacidade', '', array('id'=>'Capacidade','size'=>10, 'alt'=>'999')); 
            ?>
            <br/>
        </div>
        <div class="row sameLine">
            <label for="Professor">Professor<span class="required">*</span></label>
            <?php
                echo CHtml::textField('Professor', '', array('id'=>'Professor')); 
            ?>
            <br/>
        </div>
        <div class="row sameLine">
            <label for="HR_INI">Hora Inicio<span class="required">*</span></label>
            <?php
                $dados = MethodUtils::getArrayHora();
                echo CHtml::dropDownList('HR_INI', '', $dados, ''); 
            ?>
            <br/>
        </div>
        <div class="row sameLine">
            <label for="HR_FIM">Hora Fim<span class="required">*</span></label>
            <?php
                $dados = MethodUtils::getArrayHora();
                echo CHtml::dropDownList('HR_FIM', '', $dados, ''); 
            ?>
            <br/>
        </div>
        <div class="row">
            <label>Recursos</label>
            <table>
                <?php
                    $dados = $modelAR->getRecursos();
                    $i = 0;
                    $echo = '';
                    foreach ($dados as $key => $value) {
                        if ($i%2 == 0){
                            $echo .= '<tr>';
                        }
                        $echo .= '<td><input type="checkbox"'.
                                ' id="Recurso_'.$i.'"'.
                                ' class="Recurso" '.
                                ' value="' . $key . '"'.
                                ' /></td>';
                        $echo .= '<td><label for="Recurso_'.$i.'">'. $value . '</label></td>';
                        $echo .= '<td><input '.
                                ' id="RecursoQtde_'.$i.'"'.
                                ' class="RecursoQtde" '.
                                ' size="2"'.
                                ' maxlength="3"'.
                                ' alt="999"'.
                                ' /></td>';
                        if ($i%2 != 0){
                            $echo .= '</tr>';
                        }
                        $i++;
                    }
                    echo $echo;
                ?>
            </table>
        </div>
        <div class="row">
            <input type="button" title="Adicionar" id="Adicionar" value="Adicionar" onclick="javascript:addDisciplina();"></input>
        </div>
    </div>
    <div class="grid-view" id="template-grid">
        <table id="tblCarga" class="items">
            <thead>
                <tr>
                    <th id="template-grid_hidden" class="hidden"></th>
                    <th id="template-grid_c0">Disciplina</th>
                    <th id="template-grid_c1">Turma</th>
                    <th id="template-grid_c2">Dias</th>
                    <th id="template-grid_c3">Hora Inicial</th>
                    <th id="template-grid_c4">Hora Final</th>
                    <th id="template-grid_c5">Finalidade</th>
                    <th id="template-grid_c6">Capacidade</th>
                    <th id="template-grid_c7">Professor</th>
                    <th id="template-grid_c8"></th>
                </tr>
            </thead>
            <tbody>
                <?php
                    $count = 0;
                    $ct = 0;
                    foreach ($modelCS as $value) {
                        $ct++;
                        echo '<tr id="'.$value->getId().'" class="'.($count%2==0?'even':'odd') .'">'.
                            '<td class="hidden">'.
                            '<input type="hidden" id="disciplina" name="CargaSemestral['.$ct.'][disciplina]" value="'.$value->disciplina.'" />'.
                            '<input type="hidden" id="turma" name="CargaSemestral['.$ct.'][turma]" value="'.$value->turma.'" />'.
                            '<input type="hidden" id="dias" name="CargaSemestral['.$ct.'][diasSemana]" value="'.$value->diasSemana.'" />'.
                            '<input type="hidden" id="finalidade" name="CargaSemestral['.$ct.'][finalidade]" value="'.$value->finalidade.'" />'.
                            '<input type="hidden" id="finalidadeText" name="CargaSemestral['.$ct.'][finalidadeText]" value="'.$value->finalidadeText.'" />'.
                            '<input type="hidden" id="recursos" name="CargaSemestral['.$ct.'][recursos]" value="'.$value->recursos.'" />'.
                            '<input type="hidden" id="ini" name="CargaSemestral['.$ct.'][horaIni]" value="'.$value->horaIni.'" />'.
                            '<input type="hidden" id="fim" name="CargaSemestral['.$ct.'][horaFim]" value="'.$value->horaFim.'" />'.
                            '<input type="hidden" id="capacidade" name="CargaSemestral['.$ct.'][capacidade]" value="'.$value->capacidade.'" />'.
                            '<input type="hidden" id="professor" name="CargaSemestral['.$ct.'][professor]" value="'.$value->professor.'" />'.
                            '</td>'.
                            '<td>'.$value->disciplina.'</td>'.
                            '<td class="turma">'.$value->turma.'</td>'.
                            '<td>'.$value->diasSemana.'</td>'.
                            '<td>'.MethodUtils::getTimeFromInt($value->horaIni).'</td>'.
                            '<td>'.MethodUtils::getTimeFromInt($value->horaFim).'</td>'.
                            '<td>'.$value->finalidadeText.'</td>'.
                            '<td>'.$value->capacidade.'</td>'.
                            '<td>'.$value->professor.'</td>'.
                            '<td><a href="javascript:edit(\''.$value->getId().'\');"><img alt="Editar" src="/alocainf/assets/884ba3ad/gridview/update.png"></a><a href="javascript:remove(\''.$value->getId().'\');"><img alt="Excluir" src="/alocainf/assets/884ba3ad/gridview/delete.png"></a></td>'.
                            '</tr>';
                        $count++;
                    }
                ?>
            </tbody>
        </table>
        <input id="counter" type="hidden" value="<?php echo $ct ?>" />
    </div>
    <div class="row buttons">
        <?php echo CHtml::submitButton('Avançar'); ?>
    </div>
    </div><!-- form -->
<?php $this->endWidget(); ?>